#include "gameboard.h"
#include <QLabel>
#include <QDoubleSpinBox>
#include <QGroupBox>
#include <QCheckBox>

GameBoard::GameBoard(QWidget *parent) : QWidget(parent)
{
    QVBoxLayout *mainLayout = new QVBoxLayout(this);
    scene = new GameScene(this);
    mainLayout->addLayout(createCtrlPanel());
    mainLayout->addWidget(scene);
}

QHBoxLayout *GameBoard::createCtrlPanel()
{
    QHBoxLayout *ctrlLayout = new QHBoxLayout;
    QLabel *kpxLabel = new QLabel(tr("kp:"));
    QDoubleSpinBox *kpxSpinBox = new QDoubleSpinBox(this);
    kpxSpinBox->setRange(0, 9999);
    connect(kpxSpinBox, SIGNAL(valueChanged(double)), scene, SLOT(setKpx(double)));

    QLabel *kixLabel = new QLabel(tr("ki:"));
    QDoubleSpinBox *kixSpinBox = new QDoubleSpinBox(this);
    kixSpinBox->setRange(0, 9999);
    connect(kixSpinBox, SIGNAL(valueChanged(double)), scene, SLOT(setKix(double)));

    QLabel *kdxLabel = new QLabel(tr("kd:"));
    QDoubleSpinBox *kdxSpinBox = new QDoubleSpinBox(this);
    kdxSpinBox->setRange(0, 9999);
    connect(kdxSpinBox, SIGNAL(valueChanged(double)), scene, SLOT(setKdx(double)));

    QGroupBox *xGroup = new QGroupBox(tr("X"));
    QHBoxLayout *xLayout = new QHBoxLayout(xGroup);
    xLayout->addWidget(kpxLabel);
    xLayout->addWidget(kpxSpinBox);
    xLayout->addStretch();
    xLayout->addWidget(kixLabel);
    xLayout->addWidget(kixSpinBox);
    xLayout->addStretch();
    xLayout->addWidget(kdxLabel);
    xLayout->addWidget(kdxSpinBox);
    xLayout->addStretch();
    ctrlLayout->addWidget(xGroup);

    QLabel *kpyLabel = new QLabel(tr("kp:"));
    QDoubleSpinBox *kpySpinBox = new QDoubleSpinBox(this);
    kpySpinBox->setRange(0, 9999);
    connect(kpySpinBox, SIGNAL(valueChanged(double)), scene, SLOT(setKpy(double)));

    QLabel *kiyLabel = new QLabel(tr("ki:"));
    QDoubleSpinBox *kiySpinBox = new QDoubleSpinBox(this);
    kiySpinBox->setRange(0, 9999);
    connect(kiySpinBox, SIGNAL(valueChanged(double)), scene, SLOT(setKiy(double)));

    QLabel *kdyLabel = new QLabel(tr("kd:"));
    QDoubleSpinBox *kdySpinBox = new QDoubleSpinBox(this);
    kdySpinBox->setRange(0, 9999);
    connect(kdySpinBox, SIGNAL(valueChanged(double)), scene, SLOT(setKdy(double)));

    QGroupBox *yGroup = new QGroupBox(tr("Y"));
    QHBoxLayout *yLayout = new QHBoxLayout(yGroup);
    yLayout->addWidget(kpyLabel);
    yLayout->addWidget(kpySpinBox);
    yLayout->addStretch();
    yLayout->addWidget(kiyLabel);
    yLayout->addWidget(kiySpinBox);
    yLayout->addStretch();
    yLayout->addWidget(kdyLabel);
    yLayout->addWidget(kdySpinBox);
    yLayout->addStretch();
    ctrlLayout->addWidget(yGroup);

    QCheckBox *windCheckbox = new QCheckBox(tr("Add Wind"));
    connect(windCheckbox, SIGNAL(stateChanged(int)), scene, SLOT(setWindOn(int)));
    ctrlLayout->addWidget(windCheckbox);

    return ctrlLayout;
}
